﻿using System;

namespace UniRx.Operators
{
	// Token: 0x02000374 RID: 884
	internal class ZipLatestObservable<T1, T2, T3, T4, T5, T6, TR> : OperatorObservableBase<TR>
	{
		// Token: 0x06001206 RID: 4614 RVA: 0x000527A8 File Offset: 0x00050BA8
		public ZipLatestObservable(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, ZipLatestFunc<T1, T2, T3, T4, T5, T6, TR> resultSelector) : base(source1.IsRequiredSubscribeOnCurrentThread<T1>() || source2.IsRequiredSubscribeOnCurrentThread<T2>() || source3.IsRequiredSubscribeOnCurrentThread<T3>() || source4.IsRequiredSubscribeOnCurrentThread<T4>() || source5.IsRequiredSubscribeOnCurrentThread<T5>() || source6.IsRequiredSubscribeOnCurrentThread<T6>())
		{
			this.source1 = source1;
			this.source2 = source2;
			this.source3 = source3;
			this.source4 = source4;
			this.source5 = source5;
			this.source6 = source6;
			this.resultSelector = resultSelector;
		}

		// Token: 0x06001207 RID: 4615 RVA: 0x00052839 File Offset: 0x00050C39
		protected override IDisposable SubscribeCore(IObserver<TR> observer, IDisposable cancel)
		{
			return new ZipLatestObservable<T1, T2, T3, T4, T5, T6, TR>.ZipLatest(6, this, observer, cancel).Run();
		}

		// Token: 0x04000ACE RID: 2766
		private IObservable<T1> source1;

		// Token: 0x04000ACF RID: 2767
		private IObservable<T2> source2;

		// Token: 0x04000AD0 RID: 2768
		private IObservable<T3> source3;

		// Token: 0x04000AD1 RID: 2769
		private IObservable<T4> source4;

		// Token: 0x04000AD2 RID: 2770
		private IObservable<T5> source5;

		// Token: 0x04000AD3 RID: 2771
		private IObservable<T6> source6;

		// Token: 0x04000AD4 RID: 2772
		private ZipLatestFunc<T1, T2, T3, T4, T5, T6, TR> resultSelector;

		// Token: 0x02000375 RID: 885
		private class ZipLatest : NthZipLatestObserverBase<TR>
		{
			// Token: 0x06001208 RID: 4616 RVA: 0x00052849 File Offset: 0x00050C49
			public ZipLatest(int length, ZipLatestObservable<T1, T2, T3, T4, T5, T6, TR> parent, IObserver<TR> observer, IDisposable cancel) : base(length, observer, cancel)
			{
				this.parent = parent;
			}

			// Token: 0x06001209 RID: 4617 RVA: 0x00052868 File Offset: 0x00050C68
			public IDisposable Run()
			{
				this.c1 = new ZipLatestObserver<T1>(this.gate, this, 0);
				this.c2 = new ZipLatestObserver<T2>(this.gate, this, 1);
				this.c3 = new ZipLatestObserver<T3>(this.gate, this, 2);
				this.c4 = new ZipLatestObserver<T4>(this.gate, this, 3);
				this.c5 = new ZipLatestObserver<T5>(this.gate, this, 4);
				this.c6 = new ZipLatestObserver<T6>(this.gate, this, 5);
				//IDisposable disposable = this.parent.source1.Subscribe(this.c1);
				//IDisposable disposable2 = this.parent.source2.Subscribe(this.c2);
				//IDisposable disposable3 = this.parent.source3.Subscribe(this.c3);
				//IDisposable disposable4 = this.parent.source4.Subscribe(this.c4);
				//IDisposable disposable5 = this.parent.source5.Subscribe(this.c5);
				//IDisposable disposable6 = this.parent.source6.Subscribe(this.c6);
				return StableCompositeDisposable.Create(new IDisposable[]
				{
					//disposable,
					//disposable2,
					//disposable3,
					//disposable4,
					//disposable5,
					//disposable6
				});
			}

			// Token: 0x0600120A RID: 4618 RVA: 0x00052998 File Offset: 0x00050D98
			public override TR GetResult()
			{
				return this.parent.resultSelector(this.c1.Value, this.c2.Value, this.c3.Value, this.c4.Value, this.c5.Value, this.c6.Value);
			}

			// Token: 0x0600120B RID: 4619 RVA: 0x000529F7 File Offset: 0x00050DF7
			public override void OnNext(TR value)
			{
				this.observer.OnNext(value);
			}

			// Token: 0x0600120C RID: 4620 RVA: 0x00052A08 File Offset: 0x00050E08
			public override void OnError(Exception error)
			{
				try
				{
					this.observer.OnError(error);
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x0600120D RID: 4621 RVA: 0x00052A40 File Offset: 0x00050E40
			public override void OnCompleted()
			{
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x04000AD5 RID: 2773
			private readonly ZipLatestObservable<T1, T2, T3, T4, T5, T6, TR> parent;

			// Token: 0x04000AD6 RID: 2774
			private readonly object gate = new object();

			// Token: 0x04000AD7 RID: 2775
			private ZipLatestObserver<T1> c1;

			// Token: 0x04000AD8 RID: 2776
			private ZipLatestObserver<T2> c2;

			// Token: 0x04000AD9 RID: 2777
			private ZipLatestObserver<T3> c3;

			// Token: 0x04000ADA RID: 2778
			private ZipLatestObserver<T4> c4;

			// Token: 0x04000ADB RID: 2779
			private ZipLatestObserver<T5> c5;

			// Token: 0x04000ADC RID: 2780
			private ZipLatestObserver<T6> c6;
		}
	}
}
